package cn.wit.summit.chwan.widgets;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * Created by Alan on 2018/7/16.
 */

public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
    private int spaceH, spaceV;

    public SpacesItemDecoration(int spaceV, int spaceH) {
        this.spaceH = spaceH;
        this.spaceV = spaceV;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        //不是第一个的格子都设一个左边和底部的间距
        outRect.bottom = spaceV;
        //由于每行都只有3个，所以第一个都是3的倍数，把左边距设为0
        if (parent.getChildLayoutPosition(view) % 2 == 0) {
            outRect.left = 0;
            outRect.right = spaceH / 2;
        } else {
            outRect.left = spaceH / 2;
            outRect.right = 0;
        }
    }
}
